package com.lswms.modules.lswms.dao.recipient;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lswms.common.dao.BaseDao;
import com.lswms.modules.lswms.entity.recipient.RecipientsEntity;
import com.lswms.modules.lswms.entity.recipient.RecipientsbackEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 归还记录
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-07-21
 */
@Mapper
public interface RecipientsbackDao extends BaseDao<RecipientsbackEntity> {
@Select(value="select lswms_Recipientsback.* ,lswms_Recipients.cardId,lswms_Recipients.recipientId,lswms_Recipients.recipient,\n"
		+ " lswms_sku.descr,lswms_codelist.listname boxstr ,b.listname lot3str,isnull(c.listname,lswms_Recipientsback.lot9) lot9str,d.listname lot10str\n"
		+ "from lswms_Recipientsback left join lswms_Recipients on lswms_Recipientsback.recipientkey = lswms_Recipients.recipientkey\n"
		+ "	left join lswms_sku  on lswms_Recipientsback.sku = lswms_sku.sku\n"
		+ "	left join lswms_codelist on lswms_Recipientsback.tobox = lswms_codelist.list and code='BOXLIST' \n"
		+ "	left join lswms_codelist b on lswms_Recipientsback.lot3 = b.list and b.code='YESORNO' \n"
		+ "	left join lswms_codelist c on lswms_Recipientsback.lot9 = c.list and c.code='NEWANDOLD' \n"
		+ "	left join lswms_codelist d on lswms_Recipientsback.lot10 = d.list and d.code='YESORNO' ${ew.customSqlSegment}")
	IPage<RecipientsbackEntity> selectPageBySql(IPage<RecipientsbackEntity> page,
			@Param(Constants.WRAPPER)QueryWrapper<RecipientsbackEntity> wrapper);

	@Select(value="select lswms_Recipientsback.* ,lswms_Recipients.cardId,lswms_Recipients.recipientId,lswms_Recipients.recipient,\n"
			+ " lswms_sku.descr,lswms_codelist.listname boxstr ,b.listname lot3str,isnull(c.listname,lswms_Recipientsback.lot9) lot9str,d.listname lot10str\n"
			+ "from lswms_Recipientsback left join lswms_Recipients on lswms_Recipientsback.recipientkey = lswms_Recipients.recipientkey\n"
			+ "	left join lswms_sku  on lswms_Recipientsback.sku = lswms_sku.sku\n"
			+ "	left join lswms_codelist on lswms_Recipientsback.tobox = lswms_codelist.list and code='BOXLIST' \n"
			+ "	left join lswms_codelist b on lswms_Recipientsback.lot3 = b.list and b.code='YESORNO' \n"
			+ "	left join lswms_codelist c on lswms_Recipientsback.lot9 = c.list and c.code='NEWANDOLD' \n"
			+ "	left join lswms_codelist d on lswms_Recipientsback.lot10 = d.list and d.code='YESORNO' ${ew.customSqlSegment}")
	List<RecipientsbackEntity> selectListBySql1(@Param(Constants.WRAPPER)QueryWrapper<RecipientsbackEntity> wrapper);
	
//	@Select(value =" select a.* ,isnull(b.backqty,0) backqty ,c.listname recipienttypestr ,d.listname statusstr,e.descr , e.factorycdoe factorycdoe, e.isuniquecode isuniquecode,"
//			+ "  f.lot1 ,f.lot2 , f.lot3 , f.lot4 , f.lot5 , f.lot6 , f.lot7 , f.lot8 , f.lot9 , f.lot10 , f.lot11 , f.lot12 , f.lot13 , f.lot14 , f.lot15  \n"
//			+ " from lswms_Recipients a left join \n"
//			+ " (select recipientkey , sum( isnull(backqty,0)) backqty from lswms_Recipientsback group by recipientkey )\n"
//			+ " b on a.recipientkey = b.recipientkey \n"
//			+ " left join lswms_codelist c on a.recipienttype = c.list and c.code='RECIPIENTTYPE' "
//			+ "	left join lswms_codelist d on a.status = d.list and d.code='RECIPIENTSTATUS'"
//			+ "	left join lswms_sku e on a.sku = e.sku  "
//			+ "	left join lswms_lot f on a.lot = f.lot   ${ew.customSqlSegment}")
//	IPage<RecipientsEntity> selectPageBySql(IPage<RecipientsEntity> page, @Param(Constants.WRAPPER)QueryWrapper<RecipientsEntity> wrapper);
}